package cn.edu.hitwh.yibao.controller;

import cn.edu.hitwh.yibao.form.MedicineForm;
import cn.edu.hitwh.yibao.service.MedicineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

@Controller
public class MedicineController {
    @Autowired
    private MedicineService medicineService;

    @GetMapping("/medicine")
    public String medicine() {
        return "/medicine/select";
    }

    @PostMapping("/medicine")
    public String medicineResult(MedicineForm medicineForm, Model model) {
        return medicineService.select(medicineForm, model);
    }

    @GetMapping("/medicine/addInit")
    public String addInit(){
        return "/medicine/add";
    }

    @PostMapping("/medicine/add")
    public String add(MedicineForm medicineForm, Model model) {
        return medicineService.add(medicineForm, model);
    }

    @GetMapping("/medicine/addComplete")
    public String addComplete(Model model) {
        model.addAttribute("addResult", "添加新药品信息成功！");
        return "/medicine/select";
    }

    @GetMapping("/medicine/updateInit")
    public String updateInit(String medId, Model model) {
        return medicineService.updateInit(medId,  model);
    }

    @PostMapping("/medicine/update")
    public String update(MedicineForm medicineForm, Model model) {
        return medicineService.update(medicineForm, model);
    }

    @GetMapping("/medicine/updateComplete")
    public String updateComplete() {
        return "/medicine/select";
    }

    @GetMapping("/medicine/delete")
    public String delete(String medId, Model model) {
        return medicineService.delete(medId,  model);
    }

    @GetMapping("/medicine/deleteComplete")
    public String deleteComplete(Model model) {
        model.addAttribute("deleteResult", "删除设施信息成功！");
        return "/medicine/select";
    }

    @GetMapping("/medicine/detail")
    public String detail(String medId, Model model) {
        return medicineService.detail(medId,  model);
    }
}
